package com.pojoin.cms.exception;

@SuppressWarnings("serial")
public class CmsException extends Exception {

	private Throwable exception;
	private String message;

	@Override
	public String getMessage() {
		return exception.getMessage();
	}

	public CmsException(String message) {
		this.message = message;
	}

	@Override
	public String getLocalizedMessage() {
		if (this.exception != null) {
			return this.exception.getLocalizedMessage();
		} else {
			return this.message;
		}
	}

	@Override
	public StackTraceElement[] getStackTrace() {
		if (this.exception != null) {
			return this.exception.getStackTrace();
		} else {
			return this.getStackTrace();
		}
	}

	@Override
	public String toString() {
		if (this.exception != null) {
			return this.exception.toString();
		} else {
			return this.message;
		}
	}

	public CmsException setException(Exception e) {
		this.exception = e;
		return this;
	}
}
